from one import cover_width_func
from openpyxl import load_workbook
import math
import os


def depth_func(center_depth, forward_distance, slope):
    # the forward is deeper
    return center_depth + forward_distance * math.tan(slope)


def equivalent_cover_witdh_func(center_depth, forward_distance, b, slope):
    equivalent_cover_slope = math.atan(math.tan(slope) * math.sin(b))
    equivalent_depth_slope = math.atan(math.tan(slope) * math.cos(b))
    depth = center_depth + forward_distance * math.tan(equivalent_depth_slope)
    cover_width = cover_width_func(depth, equivalent_cover_slope)
    return cover_width


def two():
    slope = math.radians(1.5)
    center_depth = 120
    forward_distace_list = [0, 0.3, 0.6, 0.9, 1.2, 1.5, 1.8, 2.1]
    forward_distace_list = [
        forward_distace * 1852 for forward_distace in forward_distace_list
    ]
    b_list = [0, 45, 90, 135, 180, 225, 270, 315]
    b_list = [math.radians(b) for b in b_list]
    # print
    for b in b_list:
        for forward_distance in forward_distace_list:
            print(
                equivalent_cover_witdh_func(center_depth, forward_distance, b, slope),
                end="\t",
            )
        print()
    # save file
    row = 3
    col = 3
    wb = load_workbook("result2.xlsx")
    ws = wb.active
    for b in b_list:
        for forward_distance in forward_distace_list:
            ws.cell(
                row=row,
                column=col,
                value=equivalent_cover_witdh_func(
                    center_depth, forward_distance, b, slope
                ),
            )
            col += 1
        row += 1
        col = 3

    os.makedirs("output", exist_ok=True)
    wb.save("output/result2.xlsx")


if __name__ == "__main__":
    two()
